﻿using System;
namespace Library.OrmEnterpriseEntity {
	/// <summary>
	/// Wrap to sql join statement
	/// </summary>
	public class JoinStatement : QueryBuilder {
		/// <summary>
		/// 
		/// </summary>
		/// <param name="joinTable"></param>
		/// <exception cref="System.ArgumentNullException"></exception>
		public JoinStatement(GlobalEntityView joinTable)
			: this(joinTable, null) {

		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="joinTable"></param>
		/// <param name="jointExpression"></param>
		/// <exception cref="System.ArgumentNullException">throw when joinTable is null</exception>
		public JoinStatement(GlobalEntityView joinTable, QueryExpBuilder jointExpression) {
			if (joinTable == null)
				throw new ArgumentNullException("joinTable");
			JoinTable = joinTable;
			JoinExpression = jointExpression;
		}
		public GlobalEntityView Root { get; internal set; }
		public GlobalEntityView JoinTable { get; private set; }
		public QueryExpBuilder JoinExpression { get; set; }
		public virtual JoinType JoinType { get { return JoinType.Join; } }
		public override QueryStatement Statement {
			get {
				return base.Statement;
			}
			set {
				base.Statement = value;
				if (JoinExpression != null) {
					JoinExpression.Statement = value;
				}
			}
		}
	}
}
